using UnityEngine;

public class Arc : MonoBehaviour
{
	private GameManager SkinChoose;

	public GameObject[] arrow;

	public GameObject[] SuperBullet;

	public Vector2 BulletSpeed;

	public float Speed;

	public int CoolDownShoot;

	public bool PlayerOneOrTwo;

	public LeftJoystick leftJoystick;

	public RightJoystick rightJoystick;

	public Vector2 direction;

	public Vector2 SecondBrasDirection;

	public Vector2 Power;

	public int timeFirsAtt;

	public bool PowerhitReady;

	public bool directionChosen;

	public int Cooldown;

	public int CooldownUlt;

	public Rigidbody2D rb;

	public float speedDep;

	public SpriteRenderer gunsprite;

	public float maniment;

	public GameObject AvantBras;

	public GameObject AvantBras2;

	public GameObject Bras;

	public GameObject BrasCorrection;

	public GameObject AttachFil1;

	public GameObject AttachFil2;

	private PlayerDirection DirPlayer;

	public bool JoystickOnZero;

	public LineRenderer ArcFil;

	public GameObject PlayerParent;

	public GameObject Corps;

	public float dash;

	public AudioSource source;

	public AudioClip PowerAbility;

	private GameManager gManag;

	public GameObject Manager;

	public GameObject Camera;

	private void Start()
	{
		if (source == null)
		{
			source = GameObject.Find("SoundEffect").GetComponent<AudioSource>();
		}
		Manager = GameObject.Find("GameManager");
		gManag = Manager.GetComponent<GameManager>();
		SkinChoose = GameObject.Find("GameManager").GetComponent<GameManager>();
		rb = GetComponent<Rigidbody2D>();
		if (PlayerOneOrTwo)
		{
			DirPlayer = GameObject.Find("bout2").GetComponent<PlayerDirection>();
		}
		BrasCorrection.gameObject.GetComponent<HingeJoint2D>().useLimits = true;
		JointAngleLimits2D limits = BrasCorrection.gameObject.GetComponent<HingeJoint2D>().limits;
		limits.min = -1f;
		limits.max = 1f;
		BrasCorrection.gameObject.GetComponent<HingeJoint2D>().limits = limits;
	}

	private void LateUpdate()
	{
		if (Cooldown < 50)
		{
			ArcFil.SetPosition(0, new Vector3(AttachFil1.transform.position.x, AttachFil1.transform.position.y, -2f));
			ArcFil.SetPosition(1, new Vector3(AttachFil1.transform.position.x, AttachFil1.transform.position.y, -2f));
			ArcFil.SetPosition(2, new Vector3(AttachFil2.transform.position.x, AttachFil2.transform.position.y, -2f));
		}
		if (Cooldown <= 0)
		{
			ArcFil.SetPosition(0, new Vector3(AttachFil1.transform.position.x, AttachFil1.transform.position.y, -2f));
			ArcFil.SetPosition(1, new Vector3(AttachFil1.transform.position.x, AttachFil1.transform.position.y, -2f));
			ArcFil.SetPosition(2, new Vector3(AttachFil2.transform.position.x, AttachFil2.transform.position.y, -2f));
			if (direction.magnitude > 0.2f)
			{
				ArcFil.SetPosition(1, new Vector3(Bras.transform.position.x, Bras.transform.position.y, -2f));
				ArcFil.SetPosition(0, new Vector3(AttachFil1.transform.position.x, AttachFil1.transform.position.y, -2f));
				ArcFil.SetPosition(2, new Vector3(AttachFil2.transform.position.x, AttachFil2.transform.position.y, -2f));
			}
		}
	}

	private void FixedUpdate()
	{
		CooldownUlt--;
		CoolDownShoot++;
		Cooldown--;
		timeFirsAtt++;
		if (CooldownUlt == 140)
		{
			SpriteRenderer[] componentsInChildren = PlayerParent.gameObject.GetComponentsInChildren<SpriteRenderer>();
			foreach (SpriteRenderer spriteRenderer in componentsInChildren)
			{
				spriteRenderer.color = new Color(spriteRenderer.color.r, spriteRenderer.color.g, spriteRenderer.color.b, 1f);
				if (!PlayerOneOrTwo)
				{
					spriteRenderer.gameObject.layer = 8;
				}
				else if (!gManag.TwoPlayerSurvival)
				{
					spriteRenderer.gameObject.layer = 11;
				}
				else
				{
					spriteRenderer.gameObject.layer = 8;
				}
			}
		}
		if (CooldownUlt < 0)
		{
			if (!PlayerOneOrTwo)
			{
				gunsprite.color = new Color(0f, 0.7f, 1f);
			}
			else
			{
				gunsprite.color = new Color(1f, 0f, 0f);
			}
		}
		if (Cooldown <= 190)
		{
			rb.constraints = RigidbodyConstraints2D.None;
		}
		if (!PlayerOneOrTwo)
		{
			AvantBras = GameObject.Find("bras 2");
			Bras = GameObject.Find("main 2");
			if (!SkinChoose.OnePlayer)
			{
				direction = leftJoystick.GetInputDirection();
				JoystickOnZero = leftJoystick.IsTouching;
			}
			else if (!SkinChoose.LeftUser)
			{
				direction = rightJoystick.GetInputDirection();
				JoystickOnZero = rightJoystick.IsTouching;
			}
			else
			{
				direction = leftJoystick.GetInputDirection();
				JoystickOnZero = leftJoystick.IsTouching;
			}
		}
		else
		{
			AvantBras = GameObject.Find("bras 2 (3)");
			Bras = GameObject.Find("main 2d");
			if (!DirPlayer.AI)
			{
				direction = rightJoystick.GetInputDirection();
				JoystickOnZero = rightJoystick.IsTouching;
			}
			else
			{
				direction = DirPlayer.direction / 4f;
			}
		}
		direction = direction.normalized;
		rb.AddForce(direction * maniment * Time.fixedDeltaTime);
		if (direction.magnitude != 0f)
		{
			Power = direction;
		}
		if (Cooldown < 50)
		{
		}
		if (Cooldown <= 0 && direction.magnitude > 0.2f)
		{
			SecondBrasDirection = direction;
			SecondBrasDirection.y = SecondBrasDirection.y * 1.5f + 0.3f;
			AvantBras.GetComponent<Rigidbody2D>().AddForce((-direction + new Vector2(0f, 0.2f)) * 300f / 3f, ForceMode2D.Force);
			Bras.GetComponent<Rigidbody2D>().AddForce((direction + new Vector2(0f, 0.4f)) * 100f / 3f, ForceMode2D.Force);
			AvantBras2.GetComponent<Rigidbody2D>().AddForce((direction + new Vector2(0f, 0.4f)) * 100f / 4f, ForceMode2D.Force);
			if (timeFirsAtt <= 100)
			{
			}
		}
		if (CooldownUlt < 0)
		{
			if (direction.magnitude > 0.2f && timeFirsAtt > 100)
			{
				PowerhitReady = true;
			}
			if (direction.magnitude == 0f && PowerhitReady && !JoystickOnZero)
			{
				directionChosen = true;
				PowerhitReady = false;
			}
		}
		if (directionChosen)
		{
			directionChosen = false;
			CooldownUlt = 200;
			gunsprite.color = new Color(0f, 0f, 0f);
			SpriteRenderer[] componentsInChildren2 = PlayerParent.gameObject.GetComponentsInChildren<SpriteRenderer>();
			foreach (SpriteRenderer spriteRenderer2 in componentsInChildren2)
			{
				spriteRenderer2.color = new Color(spriteRenderer2.color.r, spriteRenderer2.color.g, spriteRenderer2.color.b, 0.35f);
				spriteRenderer2.gameObject.layer = 20;
			}
			Corps.GetComponent<Rigidbody2D>().AddForce(Power * dash, ForceMode2D.Impulse);
		}
		if (timeFirsAtt <= 100 || direction.magnitude == 0f)
		{
			return;
		}
		if (CoolDownShoot == 35)
		{
			source.PlayOneShot(PowerAbility);
		}
		if (CoolDownShoot < 50)
		{
			return;
		}
		CoolDownShoot = 0;
		for (int k = 0; k < SuperBullet.Length; k++)
		{
			if (!SuperBullet[k].activeInHierarchy)
			{
				Cooldown = 30;
				SuperBullet[k].SetActive(false);
				SuperBullet[k].transform.position = base.transform.position;
				SuperBullet[k].transform.rotation = base.transform.rotation;
				SuperBullet[k].transform.Translate(0f, 0.5f, 0f, Space.Self);
				SuperBullet[k].SetActive(true);
				BulletSpeed.y = Speed;
				SuperBullet[k].GetComponent<Rigidbody2D>().AddRelativeForce(BulletSpeed * 1.23f, ForceMode2D.Impulse);
				rb.constraints = RigidbodyConstraints2D.FreezeRotation;
				break;
			}
		}
	}
}
